﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace SharePoint.Contrib.Extensions
{
    /// <summary>
    /// Extension methods for the XAttribute class
    /// </summary>
    public static class XAttributeExtensions
    {
        /// <summary>
        /// Converts the value of the XAttribute to typeof(T)
        /// </summary>
        /// <typeparam name="T">Type to convert to</typeparam>
        public static T OfType<T>(this XAttribute instance)
        {
            if (instance == null)
            {
                return default(T);
            }


            if (string.IsNullOrEmpty(instance.Value) == false)
            {
                T obj = default(T);

                obj = GenericDataConverter<T>.Convert(instance.Value);
                return obj;
            }

            return default(T);

        }

    }
}
